<?php 

class Crud_Form_Decorator_SimpleFile extends Zend_Form_Decorator_Abstract
{
    /**
     * Render a form file
     *
     * @param  string $content
     * @return string
     */
    public function render($content)
    {
    	$element = $this->getElement();
    	$value = $element->getValue();
    	if (!$value) return $content;

    	$path = Config::getInstance()->file_transfer->htdocsPath;
    	$url = $path . DIRECTORY_SEPARATOR . substr($value, 0, 2). DIRECTORY_SEPARATOR . $value;
    	
		$hostname = Config::getInstance()->default->hostname ? Config::getInstance()->default->hostname : null;
		if ($hostname) $hostname = "http://$hostname";
    	if (preg_match("/(jpg|gif|png|jpeg)$/i", $value)) {
    		$prefix = "<a href='{$hostname}{$url}'><img src='{$hostname}{$url}' width='200' height='150' /></a> ";
    	} else {
    		$prefix = "<a href='{$hostname}{$url}'>{$hostname}{$url}</a> ";
    	}
    	
		$prefix = "<div id='file_prefix_{$element->getName()}' class='file_prefix'>$prefix</div>";
    	return $prefix . $content;
    }
}
